
#ifndef NODE_H
#define NODE_H

#include <QGraphicsItem>
#include <QList>

class Edge;
class GraphWidget;
QT_BEGIN_NAMESPACE
class QGraphicsSceneMouseEvent;
QT_END_NAMESPACE

class Node : public QGraphicsItem
{
public:
    Node(GraphWidget *graphWidget);
	int colorNode;
    QString nodeText;
	QString minPath; 
	void addEdge(Edge *edge);
    QList<Edge *> edges() const;
	QString getPathTo(Node* dest);
    enum { Type = UserType + 1 };
    int type() const { return Type; }

    void calculateForces();
    bool advance();
	QList<Edge *> edgeList;
    QRectF boundingRect() const;
    QPainterPath shape() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
	int createDlg(int weight, int &flagCancel);
	friend QDataStream &operator<<(QDataStream &stream, Node *node)
	{
		stream<<node->pos()<<node->nodeText;
		return stream;
	}
	friend QDataStream &operator>>(QDataStream &stream, Node *node)
	{
		QPointF buf;
		QString str;
		stream>>buf;
		stream>>str;
		node->setPos(buf);
		node->nodeText=str;
		return stream;
	}
	void controlBound();
protected:
    QVariant itemChange(GraphicsItemChange change, const QVariant &value);

    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    
private:
	QPointF newPos;
    GraphWidget *graph;
};

#endif
